<script lang="ts" setup>
import { ref, onBeforeMount, onMounted, onUnmounted } from "vue";
// import { OfficeBuilding } from "@element-plus/icons-vue";

/*企业信息接口定义 */
interface Company {
    id: string;
    name: string;
    scale: string;
    type: string;
    tags: string[];
    jobs: {
        title: string;
        salary: string;
        location: string;
        experience: string;
        education: string;
    }[];
}

/**
 * 跳转到企业详情页
 * @param id - 企业ID
 */
const gotoCompanyDetail = (id: string) => {
    router.push({
        path: "/companyInfo",
        query: { id },
    });
};

// 组件props定义
const props = defineProps<{
    companies: Company[]; // 企业列表数据
}>();

// Boss直聘logo URL
const companyLogoUrl =
    "https://img.bosszhipin.com/beijin/upload/com/logo/20210323/aab1b65662224a865a9b6ba9aceaab02babfa420ecc134d2606b05aa8114130d.png?x-oss-process=image/resize,w_100,limit_0";

// 路由实例 - 用于页面跳转
import { useRouter } from "vue-router";
const router = useRouter();

//生命周期种子
onBeforeMount(() => {});
onMounted(() => {});
onUnmounted(() => {});
</script>

<template>
    <!-- 热门企业模块 -->
    <div class="hot-companies">
        <!-- 模块标题 -->
        <h2 class="section-title">热门企业</h2>

        <!-- 企业列表展示 -->
        <el-row :gutter="20" justify="center">
            <!-- 遍历企业数据 -->
            <el-col
                v-for="(company, index) in companies"
                :key="index"
                :xs="24"
                :sm="12"
                :md="8"
                :lg="8"
                class="company-col"
            >
                <!-- 企业卡片 -->
                <el-card class="company-card" @click="gotoCompanyDetail(company.id)">
                    <!-- 卡片头部区域 -->
                    <template #header>
                        <div class="company-header">
                            <!-- 企业名称 -->
                            <div class="company-title">
                                <img :src="companyLogoUrl" class="company-logo" alt="公司logo" />
                                <span>{{ company.name }}</span>
                            </div>
                            <!-- 企业元信息 -->
                            <div class="company-meta">
                                <span>{{ company.scale }}</span>
                                <el-divider direction="vertical" />
                                <span>{{ company.type }}</span>
                            </div>
                            <!-- 企业标签 -->
                            <div class="company-tags">
                                <el-tag
                                    v-for="(tag, tagIndex) in company.tags"
                                    :key="tagIndex"
                                    type="info"
                                    size="small"
                                    class="tag-item"
                                >
                                    {{ tag }}
                                </el-tag>
                            </div>
                        </div>
                    </template>

                    <!-- 职位列表 -->
                    <div class="job-list">
                        <!-- 遍历企业发布的职位 -->
                        <div v-for="(job, jobIndex) in company.jobs" :key="jobIndex" class="job-item">
                            <!-- 职位主要信息 -->
                            <div class="job-main">
                                <span class="job-name">{{ job.title }}</span>
                                <span class="job-salary">{{ job.salary }}</span>
                            </div>
                            <!-- 职位元信息 -->
                            <div class="job-meta">
                                <span>{{ job.location }}</span>
                                <el-divider direction="vertical" />
                                <span>{{ job.experience }}</span>
                                <el-divider direction="vertical" />
                                <span>{{ job.education }}</span>
                            </div>
                        </div>
                    </div>

                    <!-- 卡片底部区域 -->
                    <template #footer>
                        <div class="card-footer">
                            <el-button class="view-detail" size="small"> 查看企业详情 </el-button>
                        </div>
                    </template>
                </el-card>
            </el-col>
        </el-row>

        <!-- 查看更多按钮 -->
        <div class="view-more-container">
            <el-button class="view-more" @click="router.push('/job')"> 查看更多 </el-button>
        </div>
    </div>
</template>

<style lang="less" scoped>
/* 热门企业模块样式 */
.hot-companies {
    max-width: 1400px;
    margin: 0 auto;
    padding: 60px 20px;

    /* 模块标题样式 */
    .section-title {
        text-align: center;
        margin-bottom: 40px;
        font-size: 32px;
        font-weight: 600;
    }

    /* 企业列样式 */
    .company-col {
        padding: 0 15px;
        margin-bottom: 30px;
    }

    /* 企业卡片样式 */
    .company-card {
        height: 100%;
        transition: all 0.3s;
        border-radius: 12px;

        /* 悬停效果 */
        &:hover {
            transform: translateY(-5px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
        }

        /* 卡片头部样式 */
        :deep(.el-card__header) {
            padding: 20px;
        }

        /* 企业头部信息样式 */
        .company-header {
            .company-title {
                display: flex;
                align-items: center;
                margin-bottom: 12px;

                .company-logo {
                    width: 24px;
                    height: 24px;
                    margin-right: 8px;
                    object-fit: contain;
                }

                span {
                    font-size: 20px;
                    font-weight: 600;
                }
            }

            .company-meta {
                color: #666;
                font-size: 14px;
                margin-bottom: 12px;
                display: flex;
                align-items: center;

                :deep(.el-divider) {
                    margin: 0 8px;
                    background-color: #ddd;
                }
            }

            /* 企业标签样式 */
            .company-tags {
                display: flex;
                flex-wrap: wrap;
                gap: 8px;

                .tag-item {
                    border-radius: 4px;
                    background: #f5f7fa;
                    border-color: #e4e7ed;
                }
            }
        }

        /* 职位列表样式 */
        .job-list {
            padding: 0 20px;

            .job-item {
                padding: 16px 0;
                border-bottom: 1px solid #eee;

                &:last-child {
                    border-bottom: none;
                }

                /* 职位主要信息样式 */
                .job-main {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    margin-bottom: 8px;

                    .job-name {
                        font-size: 15px;
                        font-weight: 500;
                    }

                    .job-salary {
                        color: #f56c6c;
                        font-weight: 600;
                    }
                }

                /* 职位元信息样式 */
                .job-meta {
                    color: #999;
                    font-size: 12px;
                    display: flex;
                    align-items: center;

                    :deep(.el-divider) {
                        margin: 0 6px;
                        background-color: #ddd;
                    }
                }
            }
        }

        /* 卡片底部样式 */
        .card-footer {
            text-align: center;
            padding: 0 20px 20px;

            .view-detail {
                width: 100%;
                background: #e6f7ff;
                border-color: #1890ff;
                color: #1890ff;
                transition: all 0.3s;

                &:hover {
                    background: #1890ff;
                    color: white;
                }
            }
        }
    }

    /* 查看更多按钮样式 */
    .view-more-container {
        text-align: center;

        .view-more {
            padding: 12px 40px;
            background-color: #e6f7ff;
            border-color: #1890ff;
            color: #1890ff;
            font-weight: bold;
            transition: all 0.3s;

            &:hover {
                background-color: #1890ff;
                color: white;
            }
        }
    }
}

/* 移动端响应式样式 */
@media (max-width: 768px) {
    :deep(.footer-container) {
        flex-direction: column;
        gap: 25px;
        padding: 30px 20px;
        text-align: center;

        .footer-section {
            flex-direction: column;
            gap: 15px;
            width: 100%;

            &.footer-links {
                flex-direction: row;
                flex-wrap: wrap;
                justify-content: center;
            }

            &.footer-social {
                flex-direction: row;
                justify-content: center;
            }
        }
    }
}
</style>
